package com.nf.dao.impl;

import com.nf.dao.SeatRowVoDao;
import com.nf.util.DBUtil;
import com.nf.vo.SeatRowVo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SeatRowVoDaoImpl implements SeatRowVoDao {
    @Override
    public List<SeatRowVo> selectByShowId(int showId) {
        List<SeatRowVo> list=new ArrayList<>();

        Connection conn= DBUtil.getConnection();
        String sql="select distinct seat_row from seatInfo where show_id=?";
        PreparedStatement pstmt=null;
        ResultSet rst=null;
        try {
            pstmt=conn.prepareStatement(sql);
            pstmt.setInt(1,showId);

            rst=pstmt.executeQuery();
            while (rst.next()){
                int row=rst.getInt(1);

                SeatRowVo seat=new SeatRowVo(row);
                list.add(seat);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DBUtil.close(rst,pstmt,conn);
        }
        return list;
    }
}
